//AC
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
using namespace std;

const int MAX_N=30+5;
const int MAX_V=2e4+5;
int V,n;
int w[MAX_N];
int dp[MAX_V];

int readint();

int main(){
    V=readint(),n=readint();
    for(int i=1;i<=n;i++){
        w[i]=readint();
    }
    for(int i=1;i<=n;i++){
        for(int j=V;j>=w[i];j--){
            dp[j]=max(dp[j],dp[j-w[i]]+w[i]);
        }
    }
    cout<<V-dp[V]<<endl;
}

int readint(){
    int x=0,w=1;
    char ch=0;
    while(!isdigit(ch)){
        if(ch=='-')w=-1;
        ch=getchar();
    }
    while(isdigit(ch)){
        x=x*10+(ch-'0');
        ch=getchar();
    }
    return x*w;
}